const obj = {
  name: "yz",
  age: 18,
  friends: [
    'haha',
    'heihei'
  ]
}

const objProxy = new Proxy(obj, {
  // 获取值时的捕获器
  get: function(target, key) {
    console.log("get访问")
    return target[key]
  },
  // 设置值时的捕获器
  set: function(target, key, newValue) {
    console.log("set设置");
    target[key] = newValue
  },
  // 监听in捕获器
  has: function(target, key) {
    console.log("监听in操作");
    return key in target
  },
  // delete捕获器
  deleteProperty: function(target, key) {
    console.log("监听delete操作");
    delete target[key]
  }
})

console.log(objProxy.name); //get访问、yz
console.log(objProxy.age); // get访问、18

objProxy.name = "jay"; // set设置
objProxy.age = 20; // set设置
console.log("哟~~~~~~");
objProxy.friends.push('son'); // get访问  不会监听到数组的改变（set）
console.log("哟~~~~~~");
 
console.log("name" in objProxy); //监听in操作 true

delete objProxy.age; // 监听delete操作

